package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.ShopMapper;
import com.qf.pojo.Shop;
import com.qf.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 高圆圆
 * @date 2023/2/6 16:07
 * 针对商品的业务接口实现
 */
@Service
public class ShopServiceImpl implements ShopService {

    //注入ShopMapper
    @Autowired
    private ShopMapper shopMapper ;

    @Override
    public List<Shop> getShops() {
       /* //设置分页:
        PageHelper.startPage() ;*/


        List<Shop> list = shopMapper.findAll();
        if(list!=null || list.size()>0){
            return list ;
        }
        return null;
    }

    /**
     * 通过商品id查询指定的商品
     * @param id
     * @return 返回商品实体
     */
    @Override
    public Shop getShopById(Integer id) {
        return shopMapper.findShopById(id) ;
    }

    /**
     * 修改商品
     * @param shop 商品实体
     * @return 返回的影响的行数
     */
    @Override
    public int updateShop(Shop shop) {
        int count = shopMapper.update(shop);
        return count;
    }

    /**
     * 删除商品
     * @param id 商品id
     * @return 影响的行数
     */
    @Override
    public int delShop(Integer id) {

        return shopMapper.del(id);
    }

    //分页查询商品
    @Override
    public PageInfo getAllShops(Integer pageNum, Integer pageSize) {
        //设置分页条件
        PageHelper.startPage(pageNum,pageSize);
        List<Shop> list = shopMapper.findAll();
        //创建PageInfo对象
        PageInfo<Shop> pageInfo = PageInfo.of(list);

        return  pageInfo;
    }
}
